﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DelegateApp1
{
    /*// 【1】声明委托
    public delegate void ReceiveDelete(string msg);*/
    public partial class FrmMain : Form
    {          
        public FrmMain()
        {
            InitializeComponent();
        }

        private void btnCreateChildForm_Click(object sender, EventArgs e)
        {
             for(int i = 1; i < 4; i++) //创建3个子窗体
            {
                FrmChild frm = new FrmChild(i);
                frm.Show();
                //【4】关联委托变量和方法
                frm.ChildReceive = ReceiveMsg;
            }
        }

        // 【2】编写具体方法
        private void ReceiveMsg(string data)
        {
            this.txtContent.Text += data + "\r\n";
        }
    }
}
